{% extends "oj_base.html" %}
{% block title %}
    比赛排名
{% endblock %}
{% block body %}
    {% load contest %}
    <div class="container main">

        <ul class="nav nav-tabs nav-tabs-google contest-tab">
            <li role="presentation">
                <a href="/contest/{{ contest.id }}/">比赛详情</a>
            </li>
            <li role="presentation">
                <a href="/contest/{{ contest.id }}/problems/">题目列表</a>
            </li>
            <li role="presentation">
                <a href="/contest/{{ contest.id }}/submissions/">提交</a>
            </li>
            <li role="presentation" class="active">
                <a href="/contest/{{ contest.id }}/rank/">排名</a>
            </li>
        </ul>

        <div class="row">
            <div class="col-lg-12 table-responsive">
                <h2 class="text-center">排名({% if contest.real_time_rank %}实时{% else %}已封榜{% endif %})
                </h2>
                {% if force_real_time_rank %}
                    <div class="alert alert-warning" role="alert">当前您使用了force_real_time_rank=true参数, 将强制显示实时结果。
                        此提示仅管理员可见。</div>
                {% endif %}
                {% if rank %}
                    <table class="table table-bordered table-condensed text-center">
                        <thead>
                        <tr>
                            <th>#</th>
                            <th class="text-center">用户名</th>
                            <th class="text-center">AC / 总提交</th>
                            <th class="text-center">用时 + 罚时</th>
                            {% for item in contest_problems %}
                                <th class="text-center">
                                    <a href="/contest/{{ contest.id }}/submissions/?problem_id={{ item.id }}">{{ item.sort_index }}</a>
                                </th>
                            {% endfor %}
                        </tr>
                        </thead>
                        <tbody class="rank">
                        {% for item in rank %}
                            <tr>
                                <th scope="row">{% if item.rank_number %}{{ item.rank_number }}{% else %}-{% endif %}</th>
                                <td>
                                <a href="/contest/{{ contest.id }}/submissions/?user_id={{ item.user__id }}">
                                    {{ item.user__username }}
                                </a>
                                    {% if show_real_name %}
                                        （{{ item.user__real_name }}）
                                    {% endif %}
                                </td>
                                <td>{{ item.total_ac_number }} / {{ item.total_submission_number }}</td>
                                <td>{% if item.total_time %}{{ item.total_time|format_seconds }}{% else %}--{% endif %}</td>
                                {% autoescape off %}
                                {% for problem in contest_problems %}
                                    <td class="{% get_submission_class item problem %}">
                                    {% get_submission_content item problem %}
                                    </td>
                                {% endfor %}
                                {% endautoescape %}
                            </tr>
                        {% endfor %}
                        </tbody>
                    </table>
                    {% include "oj/contest/_contest_auto_refresh_check.html" %}
                {% else %}
                    <p>还没有结果</p>
                    {% include "oj/contest/_contest_auto_refresh_check.html" %}
                {% endif %}

            </div>
        </div>
    </div>
{% endblock %}


{% block js_block %}
    {% if auto_refresh %}
        <script>
            setTimeout(function () {
                location.reload();
            }, 5000);
        </script>
    {% endif %}
{% endblock %}